/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package angels.conversores;

import angels.dao.GenericDAO;
import angels.modelo.Crianca;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(forClass = Crianca.class)
public class CriancaConversor implements Converter {

     GenericDAO dao = new GenericDAO();

    
     @Override
         public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            Integer i = Integer.parseInt(value);
            return dao.findByPrimaryKey(Crianca.class, i);
        } catch (NumberFormatException e) {
            return null;
        }

    }

     @Override
        public String getAsString(FacesContext context, UIComponent component, Object value) {
        return ((Crianca) value).getId().toString();
    }
}
